const Sequelize = require('sequelize');
const { sql } = require('./config')

const seq = new Sequelize(sql.database, sql.username, sql.password, {
  host: sql.host,
  port: sql.port,
  dialect: 'mysql',
  timezone: '+08:00',
  logging: false,
  pool: {
    max: 5,
    min: 0,
    idle: 10000
  },
  define: {
    freezeTableName: true,//禁止自动修改表名
    timestamps: false,//不需要添加 createdAt 和 updatedAt 两个时间戳字段
  }
});

// 连接数据库
seq.authenticate()
  .then(() => {
    console.log('========连接mysql数据库成功======');
  })
  .catch(err => {
    console.error('======连接数据库失败======', err);
  });


module.exports = seq